<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*" import="entity.Goods,entity.Connect"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品界面</title>
</head>
<body>
	<script type="text/javascript" language="javaScript">
		function add() {
			var price = document.getElementById('price').value;
			var count = document.getElementById('count').value;
			if (confirm("确定要加入购物车?")) {
				window.location.href = "hello.jsp?count="+count+"&price="+price+"&name="+text;
			}
			/* document.form1.action("hello.jsp"); */
		}
	</script>

	<script type="text/javascript">
		function fun() {
			var obj = document.getElementById("ID");
			for (i = 0; i < obj.length; i++) {//下拉框的长度就是它的选项数.
				if (obj[i].selected == true) {
					var text = obj[i].value;//获取当前选择项的 值 .
				}
			}
			var price = document.getElementById('price').value;
			var count = document.getElementById('count').value;
			var total = (count * price).toFixed(2);

			if (confirm("确定购买" + text + "支付" + total + "元吗?")) {

				window.location.href = "Goods.jsp";
			}
		}
	</script>
	<table id="tab" width="60%" border="1">
		<caption>商品清单</caption>
		<thead>
			<tr>
				<th align="center">编号</th>
				<th align="center">商品</th>
				<th align="center">价格</th>
			</tr>
		</thead>
		<tbody>
			<%
				ArrayList<Goods> goodslist = new Connect().getAllgoods();
				for (Goods e : goodslist) {
			%>
			<tr>
				<td><%=e.getId()%></td>
				<td><%=e.getName()%></td>
				<td><%=e.getPrice()%></td>
			</tr>
			<%
				}
			%>
		</tbody>
		<form id="product" method="post" action="Goods.jsp">
			<select id="ID" name="NAME">
				<%
					for (Goods e : goodslist) {
				%>
				<option value=<%=e.getName()%>><%=e.getName()%></option>
				<%
					}
				%>
			</select> 数量：<input id='count' type="text"/> 
			单价：<input id='price' type='text'>
		<%-- <%
			String price=request.getParameter("Price");
			
			out.print(price);
			%>  --%>
			<input type="submit" value="购买" onclick="fun()" /> <input
				type="button" value="添加" onclick="add()" />

		</form>
		<input type="button" value="查看购物车"
			onclick="window.location.href='hello.jsp'" />

	</table>


</body>
</html>